package zj.boxuegu.administrator.myapplication.Activity;

import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.RecyclerView;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.text.method.ScrollingMovementMethod;
import android.util.Log;
import android.webkit.WebView;
import android.widget.TextView;

import com.google.gson.Gson;

import org.xutils.common.Callback;
import org.xutils.http.RequestParams;
import org.xutils.x;

import java.net.URL;
import java.util.ArrayList;

import zj.boxuegu.administrator.myapplication.R;

public class NewsActivity extends AppCompatActivity {
    TextView textView1, textView2;
    WebView webView;
    public String contentID;
    NeswModel newsModel;

    String news2;

    public ArrayList<String> list1=new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_news);

        textView1 = (TextView) findViewById(R.id.n_textView);
        //textView2 = (TextView) findViewById(R.id.n_textView2);
        webView= (WebView) findViewById(R.id.n_webview);

        contentID = getIntent().getStringExtra("contentID").trim();

        News();
        News2();

    }

    public void News() {
        RequestParams params = new RequestParams("http://web.csmzxy.com/netCourse/readData");
        params.addQueryStringParameter("cmd", "41");


        params.addQueryStringParameter("v1", contentID);


        x.http().get(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                String news = convertString(result);

                Log.i("NewsActivity", "" + news);
                Gson gson = new Gson();

                newsModel = gson.fromJson(news, NeswModel.class);

                textView1.setText(newsModel.contentTitle);


            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {

            }

            @Override
            public void onCancelled(CancelledException cex) {

            }

            @Override
            public void onFinished() {

            }
        });
    }

    public void News2()

    {
        RequestParams params2 = new RequestParams("http://web.csmzxy.com/netCourse/readData");
        params2.addQueryStringParameter("cmd", "9");
        params2.addQueryStringParameter("v1", contentID);
        x.http().get(params2, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                news2 = convertString2(result);




                Log.i("NewsActivity", "" + news2);


               // textView2.setMovementMethod(ScrollingMovementMethod.getInstance());//滚动样式

                //textView2.setMovementMethod(LinkMovementMethod.getInstance());
               // textView2.setText(news2);

                webView.loadDataWithBaseURL(null, news2, "text/html" , "utf-8", null);



              // textView2.setText(Html.fromHtml(news2));
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {

            }

            @Override
            public void onCancelled(CancelledException cex) {

            }

            @Override
            public void onFinished() {

            }
        });
    }

    public String convertString(String result) {
        String result1 = result
                .replace(", responseSign : 00", "")
                .replace("\'", "\"")
                .replace("contentID", "\"contentID\"")
                .replace("contentAuthor", "\"contentAuthor\"")
                .replace("contentTitle", "\"contentTitle\"")
                .replace("submitTime", "\"submitTime\"");
        return result1;

    }

    public String convertString2(String result) {
        String result2 = result
                .replace(", responseSign : 00", "")
                .replace("\'", "\"")
                .replace("contentID", "\"contentID\"")
                .replace("contentAuthor", "\"contentAuthor\"")
                .replace("contentTitle", "\"contentTitle\"")
                .replace("submitTime", "\"submitTime\"");
        return result2;

    }


}
